package com.springcloud.service.impl;

import com.springcloud.pojo.Dept;
import com.springcloud.service.DeptConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author 周恒哲
 * @date 2020/02/01
 **/
@Service
public class DeptConsumerServiceImpl implements DeptConsumerService {

    @Autowired
    private RestTemplate restTemplate;//提供多种便捷访问远程http服务的方法，简单的Restful服务模板

    public static final String REST_URL_PREFIX="http://SPRINGCLOUD-PROVIDER-DEPT";

    @Override
    public boolean addDept(Dept dept) {
        return restTemplate.postForObject(REST_URL_PREFIX + "/dept/add", dept, Boolean.class);
    }

    @Override
    public Dept queryById(Long deptno) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/get/" + deptno, Dept.class);
    }

    @Override
    public List<Dept> queryAll() {
        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/list", List.class);
    }
}
